package com.huangxt.test.excel;

import java.math.BigDecimal;

public class SingleChange {
    public static double result(double a){
        return a*a;
    }

    public static Double input(double i,double f,double t,double k){
        int num = 0;
        double z =f;
        do {
            if (Math.abs(result(f)-i)<=k){
                return f;
            }
            if (Math.abs(result(t)-i)<=k){
                return t;
            }
            z=f/2+t/2;
            if((result(z)-i)/(result(t)-i)<0){
                f =z;
            }else if((result(z)-i)/(result(f)-i)<0){
                t = z;
            }else{
                return null;
            }
            num++;
        }while (num<10000);
        return null;
    }

    public static void main(String[] args) {
       // System.out.println(input(2d,-2d,2d,0.000001d));
        System.out.println(CalculationFormulaUtil.backcalculation("IRR",new BigDecimal(10000),new BigDecimal("7.5"),new BigDecimal(36)
                ,new BigDecimal("0.37"),new BigDecimal("0.005"),new BigDecimal("0.01"),new BigDecimal("100")));
        System.out.println(CalculationFormulaUtil.rateCaliberCalculation("IRR",new BigDecimal(10000),new BigDecimal("7.5"),new BigDecimal(36),
                CalculationFormulaUtil.backcalculation("IRR",new BigDecimal(10000),new BigDecimal("7.5"),new BigDecimal(36)
                        ,new BigDecimal("0.37"),new BigDecimal("0.005"),new BigDecimal("0.01"),new BigDecimal("100"))
                ));
    }
}
